package bean.wireinfo;

import java.util.List;

import javax.sound.sampled.LineEvent.Type;

import inter.wire.InterTypeinfo;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

import bean.wireanalysis.AnalysisB;
import bean.wireanalysis.AnalysisY;
import junit.framework.TestCase;
import springtest.interspring;;

public class springtest extends TestCase {
	InterTypeinfo typeinfo;
	String fristchar;
	List beanAyalysis;
	public void testA(){
		BeanFactory fac=new XmlBeanFactory(new ClassPathResource("./springsrc/testA/testB.xml"));
		interspring inters=(interspring) fac.getBean("insertspring");
		inters.sayhellow();
		inters.getfristchar();
		System.out.println(inters.getanalysislist().get(2));
		
	}
	public String getFristchar(String str){
		return str.substring(0, 1);
	}
	public InterTypeinfo getRelType(String type){
		if(type.startsWith("B")){
			typeinfo=new AnalysisB(type);
		}
		if(type.startsWith("Y")||(type.startsWith("V"))){
			typeinfo=new AnalysisY(type);
		}
		if(type.startsWith("Y")||(type.startsWith("V"))){
			typeinfo=new AnalysisY(type);
		}
		if(type.startsWith("Y")||(type.startsWith("V"))){
			typeinfo=new AnalysisY(type);
		}
		return typeinfo;
	}
	public void testB(){
		InterTypeinfo type=getRelType("YJV22");
		System.out.println(type.getClass());
	}
	public void testC(){
		try {
			typeinfo  = (InterTypeinfo) Class.forName("bean.wireanalysis.AnalysisB").newInstance();
			System.out.println(typeinfo.getClass());
			
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	public void testD() throws InstantiationException, IllegalAccessException, ClassNotFoundException{
		BeanFactory fac=new XmlBeanFactory(new ClassPathResource("./springsrc/testA/testB.xml"));
		interspring inters=(interspring) fac.getBean("insertspring");
		for(int i=0;i<inters.getanalysislist().size();i++){
			String strlist=(String) inters.getanalysislist().get(i);
			System.out.println(strlist.substring(strlist.length()-1));
			if("KVV".substring(0,1).equals(strlist.substring(strlist.length()-1)))
				typeinfo  = (InterTypeinfo) Class.forName(strlist).newInstance();
		}
		System.out.println(typeinfo.getClass());
	}
	public void testE(){
		String[] a={"ab","cd"};
		System.out.println(a.length);
	}
}
